package br.unip.tcc.domotic.orm;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "condicao")
public class Condition extends AbstractORM {
	
	private static final long serialVersionUID = 1L;
	
	private Integer conditionId;
	private String conditionName;
	private Double conditionValue;
	private Boolean conditionIsDate;
	private Boolean conditionIsHour;
	private Sensor sensor;
	private OperatorType operatorType;
	private Set<Event> events = new HashSet<Event>(0);
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "cod_condicao", unique = true, nullable = false)
	public Integer getConditionId() {
		return conditionId;
	}
	
	public void setConditionId(Integer conditionId) {
		this.conditionId = conditionId;
	}
	
	@Column(name = "nom_condicao", nullable = false)
	public String getConditionName() {
		return conditionName;
	}
	
	public void setConditionName(String conditionName) {
		this.conditionName = conditionName;
	}
	
	@Column(name = "val_condicao", nullable = false)
	public Double getConditionValue() {
		return conditionValue;
	}
	
	public void setConditionValue(Double conditionValue) {
		this.conditionValue = conditionValue;
	}
	
	@Column(name = "is_data", nullable = false)
	public Boolean getConditionIsDate() {
		return conditionIsDate;
	}
	
	public void setConditionIsDate(Boolean conditionIsDate) {
		this.conditionIsDate = conditionIsDate;
	}
	
	@Column(name = "is_hora", nullable = false)
	public Boolean getConditionIsHour() {
		return conditionIsHour;
	}
	
	public void setConditionIsHour(Boolean conditionIsHour) {
		this.conditionIsHour = conditionIsHour;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "cod_sensor", nullable = false)
	public Sensor getSensor() {
		return sensor;
	}
	
	public void setSensor(Sensor sensor) {
		this.sensor = sensor;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "cod_tipo_operador", nullable = false)
	public OperatorType getOperatorType() {
		return operatorType;
	}
	
	public void setOperatorType(OperatorType operatorType) {
		this.operatorType = operatorType;
	}
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "condicoes_evento", 
		joinColumns = { @JoinColumn(name = "cod_condicao", nullable = false, updatable =  false) }, 
		inverseJoinColumns = { @JoinColumn(name = "cod_evento", nullable = false, updatable = false) })
	public Set<Event> getEvents() {
		return events;
	}
	
	public void setEvents(Set<Event> events) {
		this.events = events;
	}
	
}
